/*
 * gmod.h -- definitions 
 *
 * Copyright (C) 2011 Saeedm <saeed.tx@gmail.com>
 *
 * The source code in this file can be freely used, adapted,
 * and redistributed in source or binary form, so long as an
 * acknowledgment appears in derived source files.  
 * No warranty is attached;
 * we cannot take responsibility for errors or fitness for use.
 */
#ifndef _gpmod_h_
#define _gpmod_h_


/*
 * Macros to help debugging
 */

#undef PDEBUG             /* undef it, just in case */
#ifdef SETH_DEBUG
#  ifdef __KERNEL__
     /* This one if debugging is on, and kernel space */
#    define PDEBUG(fmt, args...) printk( KERN_DEBUG "snull: " fmt, ## args)
#  else
     /* This one for user space */
#    define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
#  endif
#else
#  define PDEBUG(fmt, args...) /* not debugging: nothing */
#endif

#undef PDEBUGG
#define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */



#define PROCFS_MAX_SIZE		1024
#define PROCFS_NAME 	   "gmod"

#define NAME_MAXSZ (64)
#define DESCR_MAXSZ (1024)

typedef void* (*gmod_parse)(const char *buffer, unsigned long count,void* data);
typedef int (*gmod_run)(void* input_data, void *data);

struct gmod_op {
	char name[NAME_MAXSZ];
	char descr[DESCR_MAXSZ];
	gmod_parse op_parse;
	gmod_run op_run;
	void* data;
	struct gmod_op* next;
};

struct gmod_op* op_head = NULL;
struct gmod_op* op_tail = NULL;

inline void register_operation(struct gmod_op* operation){
	if (operation == NULL)
		return;
	printk(KERN_INFO "registering operation : %s\n" , operation->name);
	operation->next=NULL;
	if (op_head == NULL){
		op_head = operation;
		op_tail = operation;
		return;
	}
	op_tail->next = operation;
	op_tail = operation;
};



/******************************** INFO OPERATION *********************************/

void* info_parse(const char *buffer,unsigned long int count,void *data)
{
	printk(KERN_INFO "op info parse called \n");
	return NULL;
}

/**
 * This function is called with the /proc file is written
 *
 */
int info_run(void* input_data, void *data)
{
	struct gmod_op* op;
	printk(KERN_INFO "INFO :- \n");
	for (op = op_head;op != NULL ; op=op->next){
		printk(KERN_INFO "/proc/%s/%s : %s \n",PROCFS_NAME ,op->name, op->descr);
	}
	return 0;
}

struct gmod_op info_op = {
	.name = "info",
	.descr = "display information about current registerd operations",
	.op_parse = info_parse,
	.op_run = info_run,
	.data = NULL,
	.next = NULL
};
/********************************************************************************/
#endif
